package com.ryan.dispatcher.comp.touch;

import com.ryan.ohos.extension.event.DispatchHelper;
import com.ryan.ohos.extension.event.impl.ViewGroupHelper;
import com.ryan.ohos.extension.event.interfaces.ViewGroup;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.StackLayout;
import ohos.app.Context;
import ohos.multimodalinput.event.TouchEvent;

public class ViewMid extends StackLayout implements Component.TouchEventListener, ViewGroup {

    private ViewGroupHelper impl;

    public ViewMid(Context context) {
        super(context);
        init();
    }

    public ViewMid(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init();
    }

    public ViewMid(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init();
    }

    private void init() {
        impl = new ViewGroupHelper(this);
        setTouchEventListener(this);
    }

    @Override
    public boolean onTouchEvent(Component component, TouchEvent event) {
        return DispatchHelper.dispatch(component, event);
    }

    @Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        impl.requestDisallowInterceptTouchEvent(disallowIntercept);
    }

    @Override
    public boolean onInterceptTouchEvent(TouchEvent ev) {
        return false;
    }

    @Override
    public boolean dispatchTouchEvent(TouchEvent event) {
        return impl.dispatchTouchEvent(event);
    }

    @Override
    public boolean onTouchEvent(TouchEvent event) {
        return false;
    }

    @Override
    public boolean isConsumed() {
        return impl.isConsumed();
    }
}
